home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scm / slib / promise.scm < prev    next >
Text File  |  1999-04-19  |  902b  |  30 lines

  1. ;;;"promise.scm" promise for force and delay
  2. ;;; From Revised^4 Report on the Algorithmic Language Scheme
  3. ;;; Editors: William Clinger and Jonathon Rees
  4. ;
  5. ; We intend this report to belong to the entire Scheme community, and so
  6. ; we grant permission to copy it in whole or in part without fee.  In
  7. ; particular, we encourage implementors of Scheme to use this report as
  8. ; a starting point for manuals and other documentation, modifying it as
  9. ; necessary.
  10.  
  11. (define promise:force (lambda (object) (object)))
  12.  
  13. (define make-promise
  14.   (lambda (proc)
  15.     (let ((result-ready? #f)
  16.       (result #f))
  17.       (lambda ()
  18.     (if result-ready?
  19.         result
  20.         (let ((x (proc)))
  21.           (if result-ready?
  22.           result
  23.           (begin (set! result-ready? #t)
  24.              (set! result x)
  25.              result))))))))
  26.  
  27. ;;; change occurences of (DELAY <expression>) to
  28. ;;; (MAKE-PROMISE (LAMBDA () <expression>))
  29. ;;; and (define force promise:force)
  30.